package com.zy.dpbc.webdemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MotionEvent
import android.view.View
import android.widget.EditText
import android.widget.TextView

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val demoHtmlView = findViewById<DemoHtmlView>(R.id.web_view)
        val input = findViewById<EditText>(R.id.input_text)
        findViewById<TextView>(R.id.btn_send).setOnClickListener {
            demoHtmlView.sendData(input.text.toString().trim())
        }
        demoHtmlView.setOnTouchListener{v, event->
            when(event.action) {
                MotionEvent.ACTION_DOWN, MotionEvent.ACTION_UP -> {
                    if(!demoHtmlView.hasFocus()) {
                        demoHtmlView.requestFocusFromTouch()
                    }
                }
            }
            return@setOnTouchListener false
        };
    }
}